﻿using DemoWebapi01.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace DemoWebapi01.EntityTypeConfiguration
{
    public class QuestionOptionETConfig : BaseEntityETConfig<QuestionOption>
    {
        protected override void ConfigureOtherProperties(EntityTypeBuilder<QuestionOption> builder)
        {
            // 配置基本属性
            builder.Property(e => e.Content)
                .IsRequired()
                .HasComment("问题内容");

            builder.Property(e => e.ContentCN)
                .HasComment("问题内容(中文)");
            builder.Property(e => e.IsCorrect)
                .HasDefaultValue(false)
                .HasComment("是否正确答案");

            builder.HasOne(x => x.Question).WithMany(x => x.QuestionOptions).HasForeignKey(x => x.QuestionId).OnDelete(DeleteBehavior.Restrict) // 防止误删除引用的分类
                .HasConstraintName("FK_QuestionOption_Question");
        }
    }
}
